package com.spring.core;

/**
 * Copyright (c) 2018-2023 ThunderSoft
 * All Rights Reserved by Thunder Software Technology Co., Ltd and its affiliates.
 * You may not use, copy, distribute, modify, transmit in any form this file
 * except in compliance with ThunderSoft in writing by applicable law.
 */

import java.util.function.Function;

/**
 * @author liyuncong
 * @version 1.0
 * @file AttributeAccessor
 * @brief AttributeAccessor
 * @details AttributeAccessor
 * @date 2023-02-23
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2023-02-23                  liyuncong          Created
 */
public interface AttributeAccessor {

    void setAttribute(String name, Object value);

    Object getAttribute(String name);

    @SuppressWarnings("unchecked")
    default <T> T computeAttribute(String name, Function<String, T> computeFunction) {
        // TODO Assert
        Object value = getAttribute(name);
        if (value == null) {
            value = computeFunction.apply(name);
            setAttribute(name, value);
        }
        return (T) value;
    }

    Object removeAttribute(String name);

    boolean hasAttribute(String name);

    String[] attributeNames();
}
